﻿using MediatR;
using W.Purchase.API.Application.Command.ClientCommand;
using W.Purchase.Domain;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler.ClientCommandHandler
{
    public class UnitAddCommandHandler : IRequestHandler<UnitAddCommand, int>
    {
        private readonly IUnitRepository unitRepository;
        public UnitAddCommandHandler(IUnitRepository unitRepository)
        {
            this.unitRepository = unitRepository;
        }

        public async Task<int> Handle(UnitAddCommand request, CancellationToken cancellationToken)
        {
            request.IsDelete = false;
            request.CreateTime = DateTime.Now;
            return await unitRepository.AddAsync(new Domain.Unit()
            {

                UnitNo = request.UnitNo,
                UnitName = request.UnitName,
                UnitRemarks = request.UnitRemarks,
                CreateName = request.CreateName,
                CreateTime = request.CreateTime,
                UpdateName = request.UpdateName,
                UpdateTime = request.UpdateTime,
                DeleteName = request.DeleteName,
                DeleteTime = request.DeleteTime,
                IsDelete = request.IsDelete,
                office_id = request.office_id,
                user_id = request.user_id,

            });
        }
    }
}
